package com.xy.generate.generator;

import java.io.File;

public class MainGenerator {
    public static void doGenerate(Object model) {
        String projectPath = System.getProperty("user.dir");
        File parentFile = new File(projectPath).getParentFile();
        File file = new File(parentFile, "xy-generate-demo-project/acm-template");
        String parentPath = file.getAbsolutePath();
        StaticFileGenerator.copyFilesByRecursive(parentPath, projectPath);
        String inputDynamicPath = projectPath + File.separator + "src/main/resources/templates/MainTemplate.java.ftl";
        // dynamic
        // 兼容target目录执行
        if (projectPath.endsWith("target")) {
            inputDynamicPath = projectPath + "classes/templates/MainTemplate.java.ftl";
            projectPath = projectPath.replace("target", "");
        }
        String outDynamicPath = projectPath + File.separator + "MainTemplate.java";
        DynamicFileGenerator.doGenerate(inputDynamicPath, outDynamicPath, model);
    }
}
